package com.pyb.java.network;

import com.google.gson.Gson;

import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;

public class RequestBodyUtil {

    /**
     * 获取请求体上传类型
     * @return
     */
    public static MediaType getJsonType(){
        MediaType parse = MediaType.parse("application/json;charset=UTF-8");
        return parse;
    }

    /**
     * 获取请求体的字符串
     */
    public static RequestBody getRequestBody(String json){
        RequestBody requestBody = RequestBody.create(getJsonType(), json);
        return requestBody;
    }

    public static RequestBody getRequestBodyByMap(Map<String, Object> map)  {
        String toJson = new Gson().toJson(map);
        return getRequestBody(toJson);
    }
}
